package top.lingchen.blogapi.handler;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import top.lingchen.blogapi.vo.Result;

import static top.lingchen.blogapi.vo.ErrorCode.SYSTEM_ERROR;

/**
 * @Author 凌宸
 * @create 2021-12-16 下午 3:56
 * @Description
 * @Version 1.0
 */
// 对加了 @Controller 注解的方法进行拦截处理
@ControllerAdvice
public class AllExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result doException(Exception e){
        e.printStackTrace();
        return Result.fail(SYSTEM_ERROR.getCode(), SYSTEM_ERROR.getMsg());
    }
}
